import java.io.IOException;

import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Receiver;
import javax.sound.midi.Transmitter;


public class MidiIn {
	
	public MidiDevice inputDevice;
	public Transmitter t;
	public Receiver r;

	public void main(int nDeviceIndex)
	throws Exception
	{
		MidiDevice.Info	info;
//		************ set device number here!!! *****************
		info = MidiCommon.getMidiDeviceInfo(8);
		inputDevice = MidiSystem.getMidiDevice(info);
		inputDevice.open();

		r = new DumpReceiver(System.out);
		try
			{
//				t = MidiSystem.getTransmitter();
				t = inputDevice.getTransmitter();
				t.setReceiver(r);

			}
		catch (MidiUnavailableException e)
			{
				System.out.println("wasn't able to connect the device's Transmitter to the Receiver:");
				System.out.println(e); 

				System.exit(1);
		}
		System.out.println("midi device:" +info);

		try
			{
				System.in.read();
			}
		catch (IOException ioe)
			{
			}

	}
	public void closeMidi(){
//		t.close();
	}
}
